package tag38_02_09.threadsWeiter;

public class Th13_synch {

	static int count;

	static Object monitor = new Object();

	public static void main(String[] args) throws InterruptedException {

		int MAX = 10000;

		Thread t1 = new Thread() {
			public void run() {
				for (int i = 0; i < MAX; i++) {
					synchronized (monitor) {
						count++;
					}
				}
			}
		};

		Thread t2 = new Thread() {
			public void run() {
				for (int i = 0; i < MAX; i++) {
					synchronized (monitor) {
						count--;
					}
				}
			}
		};

		t1.start();
		t2.start();

		t1.join();
		t2.join();

		System.out.println("count = " + count);	}

}
